﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SocialShare.BLL;
using SocialShare.DAL.Facades;
using SocialShare.BusinessEntities;
using System.Configuration;

namespace SocialShare.Web
{
    public partial class activate_account : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnActivate_Click(object sender, EventArgs e)
        {
            ConfigReader configReader = new ConfigReader();
            MemberFacade memberFacade = new MemberFacade();
            SocialShare_Members member=memberFacade.GetMemberByAuthCode(txtActivationCode.Value.Trim());
            if (member != null)
            {
                if (member.AccountStatus.HasValue && member.AccountStatus.Value == (int)MEMBER_STATUS.Active)
                {
                    divMessage.Attributes.Add("class", "error");
                    lblMessage.Text = configReader.ReadConfigurationValue(ConfigurationManager.AppSettings[APP_SETTINGS_NAME.MessageLocation.ToString()], SITE_MESSAGES.ACCOUNT_ALREADY_ACTIVATED.ToString());
                }
                else
                {
                    member.AccountStatus = (int)MEMBER_STATUS.Active;
                    member.Password = txtPassword.Value.Trim();
                    memberFacade.UpdateMember(member);
                    divMessage.Attributes.Add("class", "success");
                    lblMessage.Text = configReader.ReadConfigurationValue(ConfigurationManager.AppSettings[APP_SETTINGS_NAME.MessageLocation.ToString()], SITE_MESSAGES.OPERATION_SUCCESS.ToString());
                }
            }
            else
            {
                divMessage.Attributes.Add("class", "error");
                lblMessage.Text = configReader.ReadConfigurationValue(ConfigurationManager.AppSettings[APP_SETTINGS_NAME.MessageLocation.ToString()], SITE_MESSAGES.OPERATION_FAILED.ToString());
            }
        }
    }
}